import crypto, { Encoding } from 'crypto';
/**
 * sha256加密
 * @param input
 */
export const sha256 = (input: string) => getHash(input, 'utf-8', 'sha256');

/**
 * sha1加密
 * @param input
 */
export const sha1 = (input: string) => getHash(input, 'utf-8', 'sha1');

/**
 * 获取内容的hash值
 * @param {String} content 内容
 * @param {String} encoding 内容编码,如utf-8等 
 * @param {String} type 算法, 如MD5 sha1 等等
 * @returns {String}
 */
const getHash = (content: string, encoding: Encoding, type: string) => crypto.createHash(type).update(content, encoding).digest('hex');

